<template>
  <div class="List">
        <el-table
          :data="date.list"
          style="width: 100%"
          :header-cell-style="{background: '#eef3f7',padding: '8px'}"
          >
           <el-table-column  v-for="(val,name,index) in date.header"
           v-if="name=='imgUrl'"
              :label="val"
                
              align="center"
              :key="index"
              >
              <template slot-scope="scope">
                <el-image style="width: 100px; height: 100px"
                      :src="scope.row.imgUrl"
                      ></el-image>
              </template>
            </el-table-column>
            <el-table-column v-else
              :prop="name"
              :label="val"
              align="center">
            </el-table-column>
            <el-table-column v-if="date.operation"
              label="操作管理"
              align="center">
              <template slot-scope="information">
                  <el-button size="mini" v-for="(value,IncName,key) in date.operation"
                   :key="key"
                   @click="incident(IncName,information.row)">{{value}}</el-button>
                </template>
              </el-table-column>
        </el-table>


    <div class="Page" v-if="date.condition.pageSize<date.condition.quantity">
      <el-pagination
      background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="date.condition.pageIndex"
        :page-sizes="[20, 30, 40, 50]"
        :page-size="100"
        layout="total, sizes, prev, pager, next, jumper"
        :total="date.condition.quantity">
      </el-pagination>
    </div>
  </div>
</template>

<script>
  export default{
    inject:["reload"],
    data(){
      return{
        list:[]
      }
      },
      props:['date'],
    methods:{
      search(e){
        console.log(e)
        if(e){
          this.date.condition.fromRegTime=e[0]
          this.date.condition.toRegTime=e[1]
        }
          console.log(this.date.condition)
       //  this.Postdata(this.date.url.post,this.date.condition)
      },
      handleSizeChange(val) {
        this.date.condition.pageSize=val
         //this.PostData('admin/charge/detail/get',this.condition)
          },
       handleCurrentChange(val) {
          this.date.condition.pageIndex=val
          //this.PostData('admin/charge/detail/get',this.condition)
      },
      incident(e,r){
        // console.log(this.date)
        if(e=='del'){
         var _this=this
            this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
           confirmButtonText: '确定',
           cancelButtonText: '取消',
           type: 'warning'
         }).then(() => {
            _this.Postdata(this.date.url.del,e)
           this.$message({
             type: 'success',
             message: '删除成功!'
           });
         }).catch(() => {
           this.$message({
             type: 'info',
             message: '已取消删除'
           });
         });
        }else{
           this.$emit('fun',r,e)
        }
        //console.log(r)
      },
      Postdata(url,e){
        var _this=this
        this.$axios({
                method: "POST",
                url: '/api/'+url,
                headers: {'Content-Type': 'application/json'},
                data: {
                          adminName:_this.$cookies.get('adminName'),
                          token:_this.$cookies.get('token'),
                          userName:e.userName,
                          startTime:e.startTime,
                          endTime:e.endTime,
                          admin:e.adminName,
                          pageIndex:e.pageIndex,
                          pageSize:e.pageSize
                      },
               }).then(res=>{
                 console.log(res)
                 if(res.data.code==0){
                   if(res.data.data!=null){

                     _this.date.list=res.data.data.addCoins
                     _this.date.condition.quantity=res.data.data.sum
                   }else{
                     _this.$alert('操作成功', '提示', {
                        confirmButtonText: '确定',
                        callback: action => {
                          _this.reload()
                        }
                      });
                   }
                 }else{
                   _this.$alert('操作失败,请重试', '提示', {
                      confirmButtonText: '确定',
                      callback: action => {
                        //_this.reload()
                      }
                    });
                 }
               })
      }
    },
    mounted(){
    this.Postdata(this.date.url.post,this.date.condition)
    }
      }
</script>

<style>
  .List{
    margin-top: 15px;
  }
</style>
